//
//  ZZCSettingViewController.m
//  B段项目
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCSettingViewController.h"
#import "ZZCAboveOurViewController.h"
#import "ZZCCollectionViewController.h"
@interface ZZCSettingViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *setTableView;
@property(nonatomic,retain)MBProgressHUD *hud;
@property(nonatomic,retain)UIButton *nightBtn;

@end

@implementation ZZCSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //图标
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH - WIDTH/4.5, WIDTH/40, WIDTH/16, WIDTH/16)];
    img.image = [UIImage imageNamed:@"iconfont-wrench.png"];
    img.center = CGPointMake(WIDTH - WIDTH/5, self.navigationController.navigationBar.frame.size.height /2);
    [self.rightView addSubview:img];
    
    self.setTableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    [self.view addSubview:self.setTableView];
    
    self.setTableView.delegate = self;
    self.setTableView.dataSource = self;
    
    //去掉多余cell的线
    self.setTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //注册
    [self.setTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.setTableView.tableFooterView = [UIView new];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"关于我们";
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"我的收藏";
    }else if (indexPath.row == 2){
        cell.textLabel.text = @"登录账号";
    }else {
        cell.textLabel.text = @"清除缓存";
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //选中有置灰效果  离开自动取消
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        ZZCAboveOurViewController *aboutOurVC = [[ZZCAboveOurViewController alloc]init];
        [self.navigationController pushViewController:aboutOurVC animated:YES];
        
    }else if (indexPath.row == 2){
        
        
        UIAlertController *alertV = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否游客身份登陆" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            NSString *arc = [NSString stringWithFormat:@"%u", arc4random() % (9999999 - 1000000 + 1) + 1000000];
            
            NSString *name = [NSString stringWithFormat:@"游客%@", arc];
            
            
            [self.settingVcDeleage setNameToDrawer:name];
            
            
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            return;
            
        }];
        
        [alertV addAction:action1];
        [alertV addAction:action2];
        
        [self presentViewController:alertV animated:YES completion:^{
            
        }];
        
    }else if (indexPath.row == 3){
        
        
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        float cacheSize = size / 1024.0 / 1024.0;
        NSString *string = [NSString stringWithFormat:@"缓存大小为%.2fMB", cacheSize];
        
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:string preferredStyle:UIAlertControllerStyleActionSheet];
        
        [self presentViewController:alertC animated:YES completion:^{
            
        }];
        
        // 创建提示框按钮
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"清除缓存" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
            // 清除缓存
            [[SDImageCache sharedImageCache] clearDisk];
            // hud单例
            self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            self.hud.labelText = @"清除缓存成功";
            self.hud.mode = MBProgressHUDModeText;
            [self.hud hide:YES afterDelay:1];
        }];
        // 创建提示框按钮
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            
        }];
        // 将按钮放在提示框上
        [alertC addAction:action];
        [alertC addAction:action1];
        
        
        
        
        
    }else if(indexPath.row == 1){
        
        NSMutableArray *array = [[ZZCCollectionData collectDataBase]selectCollectList];
        
        if (array.count == 0) {
            
            self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            self.hud.labelText = @"您还有没有收藏";
            self.hud.mode = MBProgressHUDModeText;
            [self.hud hide:YES afterDelay:1.5];
        }else{
            
            
            ZZCCollectionViewController *myCollVC = [[ZZCCollectionViewController alloc]init];
            
            [self.navigationController pushViewController:myCollVC animated:YES];
            
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
